﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Projektarbete.Popup
{
    /// <summary>
    /// Creates a button
    /// </summary>
    class Button
    {
        public string text;
        public Vector2 position;

        public Rectangle hitbox;

        private VoidPointer ClickPointer;

        /// <summary>
        /// Creates a button
        /// </summary>
        /// <param name="text">text to slap onto the button</param>
        /// <param name="position">position of this button</param>
        /// <param name="ClickPointer">pointer to the method to be executed when the button is pressed</param>
        /// <param name="spriteFont">the font this button will use</param>
        public Button(string text, Vector2 position, VoidPointer ClickPointer, SpriteFont spriteFont)
        {
            this.text = text;
            this.position = position;
            this.ClickPointer = ClickPointer;

            hitbox = new Rectangle((int)position.X, (int)position.Y, (int)spriteFont.MeasureString(text).X, (int)spriteFont.MeasureString(text).Y);
        }

        /// <summary>
        /// Creates a button with a manually created hitbox
        /// </summary>
        /// <param name="text">text to slap onto the button</param>
        /// <param name="position">position of this button</param>
        /// <param name="ClickPointer">pointer to the method to be executed when the button is pressed</param>
        /// <param name="hitbox">hitbox of this button</param>
        public Button(string text, Vector2 position, VoidPointer ClickPointer, Rectangle hitbox)
        {
            this.text = text;
            this.position = position;
            this.ClickPointer = ClickPointer;
            this.hitbox = hitbox;
        }

        /// <summary>
        /// Click the button
        /// </summary>
        public void Click()
        {
            ClickPointer();
        }
    }
}
